/*
 * comlan
 */

package com.promfy.bughunter.views;


import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.promfy.bughunter.BugHunterActivity;
import com.promfy.bughunter.R;

/**
 * game back view when you press 'back' key, 
 * it contains: 
 * 1.back
 * 2.continue
 * 3.restart
 * @author mfy
 *
 */
public class GameBackView extends LinearLayout implements OnClickListener{

	
	private Handler handler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			int what = msg.what;
			switch (what) {
			
			default:
				break;
			}
			super.handleMessage(msg);
		}
		
	};
	
	private LayoutInflater inflater;

	private Context context;

	private View view;

	private static final String LOGIN_LANG = "lang";
	private static final String LOGIN_CHN = "CHN";
	private static final String LOGIN_ENG = "EN";

	private static final String TAG = "newlogin";

	private String lang;
	private int status;

	private Button resume;

	private Button restart;

	private Button exit;
	public static final int STATUS_EN = 11;
	public static final int STATUS_CHN = 12;
	
	private static GameBackView gameBackView;
	
	
	
	public static GameBackView getInstance(Context context){
		if(gameBackView == null){
			gameBackView = new GameBackView(context);
		}
		return gameBackView;
	}


	public GameBackView(Context context) {
		super(context);
		this.context = context;
	
		initView();
		initData();
	}

	
	
	public GameBackView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}



	private void initView(){
		inflater = LayoutInflater.from(context);
		view = inflater.inflate(R.layout.game_back, this);
		resume = (Button)view.findViewById(R.id.btn1_game_back);
		restart = (Button)view.findViewById(R.id.btn2_game_back);
		exit = (Button)view.findViewById(R.id.btn3_game_back);
		
		resume.setOnClickListener(this);
		restart.setOnClickListener(this);
		exit.setOnClickListener(this);
	}
	
	private void initData() {
	
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn1_game_back:
			//hide this view, resume game
			GamePlayingView.setPause(false);
			setVisibility(INVISIBLE);
			break;
		case R.id.btn2_game_back:
			//hide this view, start a new GamePlayingView
			GamePlayingView.setPause(false);
			setVisibility(INVISIBLE);
			// start a new game 
			((BugHunterActivity)context).onState(BugHunterActivity.STATUS_GAME_PLAYING);
			break;
		case R.id.btn3_game_back:
			// finish activity
			((Activity)context).finish();
			break;
		default:
			break;
		}
	}


//	private void fade(int visibility, float startDelta, float endDelta) {
//		Animation anim = new TranslateAnimation(0, 0, startDelta, endDelta);
//		anim.setDuration(ANIMATION_DURATION_TIME);
//		startAnimation(anim);
//		super.setVisibility(visibility);
//	}
//
//	@Override
//	public void setVisibility(int visibility) {
//		// TODO Auto-generated method stub
//		if(visibility == View.VISIBLE){
//			fade(visibility,  -getHeight(), 0.0f);	
//			//anim = new TranslateAnimation(0, 0, -getHeight(), 0);			
//		}else{
//			if(terminalNavigation != null){
//				terminalNavigation.reSetNavigationPositon();
//			}
//			fade(visibility, 0.0f, -getHeight());
//		}
//	}
	


}
